import { Component,ViewChild } from '@angular/core';
import { CommonService } from '../service/common.service'
import { Router } from '@angular/router'


@Component({
  selector: 'app-tab2',
  templateUrl: 'tab2.page.html',
  styleUrls: ['tab2.page.scss']
})
export class Tab2Page {

  public productlist:any;
  public filCost:number;
  public userInfo:any;
  constructor(private common:CommonService,private router:Router) {}

  ngOnInit(){
      this.userInfo = this.common.getInfo()
      this.getproduct()
      this.getCentsData()
  }


   // 刷新
   doRefresh(event) {
    setTimeout(() => {
     this.ngOnInit()
      event.target.complete();
    }, 1500);
  }


  // 首页商品展示列表
  getproduct(){  
    var api = '/tbr/getProductList'
    var params = {
      page:1,
      limit:10
    }
    this.common.post(api,params,false).then((res:any)=>{
      console.log(res)
      if(res.code == 200){
        this.productlist = res.data.records
      }
    })
  }


  getCentsData(){  
    var api = '/tbr/getCentsData'

    this.common.get(api).then((res:any)=>{
      // console.log(res)
      if(res.code == 200){
        this.filCost = res.data.filCost
      }
    })
  }

  // 跳转订单
  onConfirmorder(e){
    this.userInfo = this.common.getInfo()
    if( this.userInfo.paymentCode == "" || this.userInfo.paymentCode == null){
      this.common.presentAlertUrl("您还未设置支付密码 <br /> 请完成密码设置后进行购买",'mine/setpwd')
    }else{
      var data = JSON.stringify(e)
      this.router.navigate(['/confirmorder'],{
        queryParams: {data:data}
      })
    }
    
  }

}
